<template>
	<view class="brand-rank">
		<view class="brand-rank-navbar">
			<u-navbar
				:custom-back="back"
				back-icon-size="40"
				back-icon-name="arrow-leftward"
				back-icon-color="#000"
				title-size="38rpx"
				:title-color="titleColor"
				:title="title"
				:background="background"
				:border-bottom="false">
			</u-navbar>
		</view>
		<view class="brand-bg" :style="{marginTop: '-'+top+'px'}">
			<image src="https://jiajudashi.oss-cn-shenzhen.aliyuncs.com/images/shop/icons/recomBrand/bg.png" mode="widthFix"></image>
		</view>
		<view class="brand-tit" :style="{marginTop: '-'+titHeight+'px'}">
			<text>推荐理由：</text>在近200家工厂中，{{store_name}}精心臻选，从品味、品牌、品质三大标准中，用心精选推荐前12家优质家居品牌。
		</view>
		<block v-if="show">
			<view class="brand-list-box">
				<view class="brand-item" v-for="(data,index) in brandList" :key="index">
					<view :class="['brand-item-index',{index1: index==0,index2: index==1,index3: index==2}]">NO.{{index + 1}}</view>
					<view class="brand-item-info">
						<!-- <view :class="['index',{index1: index==0,index2: index==1,index3: index==2}]">NO.{{index + 1}}</view> -->
						<view class="brand-item-info-cell">
							<view class="label star">
								推荐指数：<pt-rate :score="data.score" :current="data.star_match" :disabled="true" normal="#717171" active="#f59359"></pt-rate>
							</view>
						</view>
						<view class="brand-item-info-cell">
							<text class="label">货期：</text>
							<text class="text">{{data.delivery}}</text>
						</view>
						<view class="brand-item-info-cell">
							<text class="label">材质：</text>
							<text class="text">{{data.texture}}</text>
						</view>
						<view class="brand-item-info-cell">
							<text class="label">定制：</text>
							<text class="text">{{data.size}}</text>
						</view>
						<view class="brand-item-info-cell">
							<text class="label">推荐理由：</text>
							<text class="text">{{data.reason}}</text>
						</view>
					</view>
					<view class="brand-item-pro">
						<view class="brand-item-pro-name">
							<image :src="data.logo" mode="aspectFit"></image>
							<view class="name-box">
								<view class="name-tit">{{data.factory_name}}</view>
								<view class="tags">
									<text v-if="data.click">人气：{{data.click}}</text>
									<text v-if="data.style">{{data.style}}</text>
								</view>
							</view>
						</view>
						<view class="brand-item-brief" v-if="data.brief">{{data.brief}}</view>
						<scroll-view class="brand-item-scroll-view" v-if="data.goods_list.length" scroll-x style="padding-top: 0;">
							<view class="brand-item-pro-item" v-for="(item,i) in data.goods_list" :key="i"  @click="goProInfo(item.goods_id)">
								<image :src="item.image" mode="aspectFill"></image>
								<view class="brand-item-pro-item-name">{{item.goods_name}}</view>
								<view class="brand-item-pro-item-price">￥<text>{{item.retail_price}}</text></view>
							</view>
						</scroll-view>
						<!-- <view class="brand-item-btn" @click="goFactoryInfo(data.factory_id)">查看详情 <u-icon name="arrow-right" color="#8F8F8F"></u-icon></view> -->
						<view style="margin-top: 50rpx;"><pt-jump-more @more="goFactoryInfo(data.factory_id)"></pt-jump-more></view>
					</view>
				</view>
			</view>
			<pt-loading-more v-if="isLoading"></pt-loading-more>
			<pt-nomore v-if="noMore && brandList.length"></pt-nomore>
		</block>
		<pt-loading></pt-loading>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				show: false,
				title: '',
				titleColor: 'rgba(0,0,0,0)',
				top: 0,
				titHeight: 0,
				background: {
					backgroundColor: 'rgba(255,255,255,0)',
				},
				page: 0,
				isLoading: false,
				noMore: false,
				brandList: [],
				// 足迹参数
				addFootParam: {
					start_time: '',
					end_time: '',
					stay_time: 0
				},
				store_name: ''
			};
		},
		onReachBottom() {
			if(!this.noMore){
				this.isLoading = true
				this.page++
				this.init()
			}
		},
		onPageScroll(e) {
			if(e.scrollTop > 20){
				this.title = '品牌排行榜'
				this.titleColor = 'rgba(0,0,0,1)'
				this.background.backgroundColor =  'rgba(255,255,255,1)'
			}else{
				this.title = ''
				this.titleColor = 'rgba(0,0,0,0)'
				this.background.backgroundColor =  'rgba(255,255,255,0)'
			}
		},
		onReady() {
			uni.createSelectorQuery().in(this).select('.brand-rank-navbar').boundingClientRect(navbarRes => {
				this.top = navbarRes.height
			}).exec()
			uni.createSelectorQuery().in(this).select('.brand-tit').boundingClientRect(res => {
				this.titHeight = res.height
			}).exec()
		},
		onLoad(options) {
			this.store_name = JSON.parse(uni.getStorageSync('userInfo')).store_name
			// 如果用户从分享的小程序卡片点击进来的,设置一个url缓存,登录后返回当前缓存url
			let pages = getCurrentPages();
			let curPage = pages[pages.length - 1];
			uni.setStorageSync('newurl',curPage.$page.fullPath)
			this.init()
			uni.loadFontFace({
				family: 'din',
				source: 'https://jiajudashi.oss-cn-shenzhen.aliyuncs.com/images/shop/icons/recomBrand/DIN-Bold.ttf',
				success: (din) => {}
			})
		},
		onHide() {
			this.addFootParam.end_time = parseInt(new Date().getTime() / 1000)
			this.addFootParam.stay_time = this.addFootParam.end_time - this.addFootParam.start_time
			if(uni.getStorageSync('userInfo')){
				this.addFoot('选品手册')
			}
		},
		onUnload() {
			this.addFootParam.end_time = parseInt(new Date().getTime() / 1000)
			this.addFootParam.stay_time = this.addFootParam.end_time - this.addFootParam.start_time
			if(uni.getStorageSync('userInfo')){
				this.addFoot('选品手册')
			}
		},
		mounted() {
			this.addFootParam.start_time = parseInt(new Date().getTime() / 1000)
		},
		methods: {
			// 足迹
			addFoot(where){
				this.$u.api.AddFoot({
					// #ifdef MP-WEIXIN
					type: 1,
					// #endif
					// #ifdef APP-PLUS
					type: 2,
					// #endif
					// #ifdef H5
					type: 3,
					// #endif
					store_id: uni.getStorageSync('userInfo')?JSON.parse(uni.getStorageSync('userInfo')).store_id:'',
					client: 1,
					where: where,
					stay_time: this.addFootParam.stay_time,
					goods_id: 0,
					store_goods_id: 0,
					is_new: 1
				})
			},
			init(){
				this.$u.api.FactoryList({is_rank: 1,page: this.page}).then(res => {
					this.show = true
					this.isLoading = false
					if(res.datas.list.length){
						res.datas.list.forEach((item,index) => {
							if(item.star.toString().indexOf('.')!=-1){
								item.score = item.star.toString().substring(item.star.toString().indexOf('.') + 1) / 10
								item.star_match = Number(item.star.toString().substring(0,item.star.toString().indexOf('.'))) + 1
							}else{
								item.score = 1
								item.star_match = item.star
							}
							this.brandList.push(item)
						})
					}else{
						this.noMore = true
					}
				})
			},
			back(){
				let pages = getCurrentPages()
				if(pages.length>1){
					uni.navigateBack()
				}else{
					// #ifdef MP-WEIXIN
					if(uni.getExtConfigSync().appid==='wx9f2da8a90bb750f7'){
						uni.switchTab({
							url: '/pages/merchant/merchant'
						})
					}else{
						uni.switchTab({
							url: '/pages/index/index'
						})
					}
					// #endif
					// #ifdef APP-PLUS || H5
					uni.switchTab({
						url: '/pages/index/index'
					})
					// #endif
				}
			},
			goFactoryInfo(factory_id){
				uni.navigateTo({
					animationDuration: 500,
					url: '/brand-list/brand-info/brand-info?type=1&factory_id='+factory_id
				})
			},
			goProInfo(goods_id){
				getApp().goProInfo(goods_id)
			}
		}
	}
</script>

<style lang="scss">
	@font-face {
		font-family: 'din';
		src: url('https://jiajudashi.oss-cn-shenzhen.aliyuncs.com/images/shop/icons/recomBrand/DIN-Bold.ttf') format('truetype');
	}
	.brand-rank{
		.brand-bg{
			image{
				width: 100%;
			}
		}
		.brand-tit{
			border-radius: 30rpx 30rpx 0 0;
			padding: 30rpx 30rpx 60rpx;
			color: rgba(255,255,255,.8);
			font-size: 24rpx;
			background-color: rgba(0,0,0,.6);
			position: relative;
			z-index: 1;
			line-height: 42rpx;
			text{
				font-weight: bold;
				color: rgba(255,255,255,1);
			}
		}
		.brand-list-box{
			margin-top: -30rpx;
			border-radius: 30rpx 30rpx 0 0;
			position: relative;
			z-index: 2;
			background-color: #FFF;
			padding: 60rpx 30rpx;
			.brand-item{
				margin-bottom: 80rpx;
				.brand-item-index{
					text-align: center;
					font-family: din;
					padding: 50rpx 0;
					font-size: 36rpx;
					&.index1{
						
					}
					&.index2{
						
					}
					&.index3{
						
					}
				}
				&:last-child{
					margin-bottom: 0;
				}
				.brand-item-info{
					background-color: #141414;
					padding: 30rpx;
					position: relative;
					border-radius: 30rpx 30rpx 0 0;
					.index{
						font-family: din;
						position: absolute;
						width: 86rpx;
						height: 86rpx;
						background: url(https://jiajudashi.oss-cn-shenzhen.aliyuncs.com/images/shop/icons/recomBrand/no4.png) no-repeat;
						background-size: cover;
						text-align: center;
						line-height: 86rpx;
						right: 20rpx;
						top: -2rpx;
						font-size: 28rpx;
						&.index1{
							background: url(https://jiajudashi.oss-cn-shenzhen.aliyuncs.com/images/shop/icons/recomBrand/no1.png) no-repeat;
							background-size: cover;
						}
						&.index2{
							background: url(https://jiajudashi.oss-cn-shenzhen.aliyuncs.com/images/shop/icons/recomBrand/no2.png) no-repeat;
							background-size: cover;
						}
						&.index3{
							background: url(https://jiajudashi.oss-cn-shenzhen.aliyuncs.com/images/shop/icons/recomBrand/no3.png) no-repeat;
							background-size: cover;
						}
					}
					.brand-item-info-cell{
						font-size: 24rpx;
						line-height: 42rpx;
						margin-bottom: 20rpx;
						&:last-child{
							margin-bottom: 0;
						}
						.label{
							color: #FFF;
							font-weight: bold;
							&.star{
								display: flex;
								align-items: center;
							}
						}
						.text{
							color: #B2B2B2;
						}
					}
				}
				.brand-item-pro{
					padding: 30rpx;
					border-radius: 16rpx;
					background-color: #FFF;
					box-shadow: -2rpx 7rpx 40rpx 0px rgba(40, 34, 31, 0.1);
					.brand-item-pro-name{
						display: flex;
						align-items: center;
						image{
							border-radius: 50%;
							border: solid 2rpx #EEE;
							width: 100rpx;
							height: 100rpx;
						}
						.name-box{
							flex: 1;
							min-width: 0;
							margin-left: 30rpx;
							.name-tit{
								font-weight: bold;
								font-size: 32rpx;
								color: #2F2F2F;
								margin-bottom: 10rpx;
							}
							.tags{
								text{
									border-right: solid 2rpx #EEE;
									padding-right: 30rpx;
									margin-right: 30rpx;
									color: #909090;
									font-size: 24rpx;
									&:last-child{
										border-right: none;
									}
								}
							}
						}
					}
					.brand-item-brief{
						color: #7E7E7E;
						font-size: 24rpx;
						line-height: 42rpx;
						margin-top: 30rpx;
					}
					.brand-item-scroll-view{
						white-space: nowrap;
						box-sizing: border-box;
						margin-top: 30rpx;
						.brand-item-pro-item{
							display: inline-block;
							width: calc((100% - 40rpx) / 3);
							margin-right: 20rpx;
							&:last-child{
								margin-right: 0;
							}
							.brand-item-pro-item-name{
								white-space: nowrap;
								overflow: hidden;
								text-overflow: ellipsis;
								margin: 25rpx 0;
								font-size: 24rpx;
							}
							.brand-item-pro-item-price{
								font-size: 20rpx;
								color: #F59359;
								text{
									font-size: 28rpx;
								}
							}
							image{
								width: 196rpx;
								height: 196rpx;
								border-radius: 8rpx;
							}
						}
					}
					.brand-item-btn{
						margin-top: 30rpx;
						border: solid 2rpx #E5E5E5;
						border-radius: 8rpx;
						height: 80rpx;
						line-height: 80rpx;
						text-align: center;
						color: #8F8F8F;
						/deep/ .u-icon{
							margin-left: 10rpx;
						}
					}
				}
			}
		}
	}
</style>
